package com.lldpet.spring.cloud.demo.payment.service.listener;

import cn.ygyg.common.utils.JsonUtils;
import com.lldpet.spring.cloud.demo.price.client.channel.PriceSource;
import com.lldpet.spring.cloud.demo.price.client.event.PriceUpdateEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.bus.event.RemoteApplicationEvent;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;

/**
 * @desc：PriceListener
 * @author: guanliang.xue
 * @date: 2021/5/12 13:37
 * @version:
 * @since:
 */
@EnableBinding(PriceSource.class)
public class PriceListener {
    private static final Logger logger = LoggerFactory.getLogger(PriceListener.class);

    @StreamListener(PriceSource.INPUT_CHANNEL)
    public void onPriceUpdateEvent(RemoteApplicationEvent remoteApplicationEvent){
        if(remoteApplicationEvent instanceof PriceUpdateEvent){
            logger.info("payment-service#PriceListener 监听到 价格更新事件");
            logger.info("PriceListener.priceUpdateEvent: {}", JsonUtils.toText(remoteApplicationEvent));
        }
        // todo 监听到事件后到业务逻辑处理

    }
}
